<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="utf-8">
    <title>登录 - 工作量计算系统</title>
    <meta HTTP-EQUIV="pragma" CONTENT="no-cache">
    <meta HTTP-EQUIV="Cache-Control" CONTENT="no-store, must-revalidate">
    <meta HTTP-EQUIV="expires" CONTENT="Wed, 26 Feb 1997 08:21:57 GMT">
    <meta HTTP-EQUIV="expires" CONTENT="0">


    <link rel="Shortcut Icon" href="../images/favicon.ico"/>
    <link rel="stylesheet" href="../src/css/layui.css">
    <link rel="stylesheet" href="../src/css/layui.css">
    <script type="text/javascript" src="../src/layui.js"></script>
    <script type="text/javascript" src="../js/jquery-3.2.1.js"></script>
    <script type="text/javascript" src="../js/jquery-3.2.1.js"></script>
    <script type="text/javascript" src="../js/jscookie.js"></script>
    <script type="text/javascript" src="../js/setting.js"></script>
    <script type="text/javascript" src="../src/layui.js"></script>
    <script type="text/javascript" src="../js/des.js"></script>
    <link rel="stylesheet" type="text/css" href="../css/register-login.css">
    <style>

        h1 {
            font-size: 2em;
            margin: .67em 0
        }

        h2 {
            font-size: 1.5em;
            margin: .75em 0
        }

    </style>
</head>
<body>
<div id="box"></div>
<div class="cent-box">
    <div class="cent-box-header">
        <h1 class="main-title">教务</h1>
        <h2 class="sub-title"> 工作量计算系统</h2>
    </div>

    <div class="cont-main clearfix">
        <!--<div class="login form" method="post">
            <div class="group">
                <div class="group-ipt email">
                    <input type="text" name="username" id="email" class="ipt" placeholder="输入您的登录账号" required>
                </div>
                <div class="group-ipt password">
                    <input type="password" name="password" id="password" class="ipt" placeholder="输入您的登录密码" required>
                </div>
            </div>
            <div class="button">
                <button class="login-btn register-btn button"  id="embed">登录</button>
            </div>
        </div>-->
        <form action="#" method="post">
            <div class="layui-form-item">
                <div class="layui-input-block" align="center">
                    <input type="text" id="username" lay-verify="required|title" required placeholder="用户名"
                           autocomplete="true" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block" align="center">
                    <input type="password" id="password" lay-verify="password" placeholder="密码" autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block" align="center">
                    <input type="text" id="captcha" placeholder="请输入验证码" autocomplete="off" class="verify layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block" align="center">
                    <img id="captchaImage" src="captcha" alt="验证码"/>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block" align="center">
                    <a class="layui-btn layui-btn-normal" id="login" href="javascript:;">登录</a>
                    <a class="layui-btn layui-btn-primary" id="reset" href="javascript:;">重置</a>
                </div>
            </div>

        </form>

        <div class="layui-row" align="center">
            <a id="forget" href="forget.html">找回密码</a>
        </div>


    </div>
    <p align="center">管理员初始账号：admin 密码：hfuter</p>
</div>

<div class="footer">
    <p>©CopyRight 2017 All Rights Reserved.</p>
</div>

<script type="text/javascript" src="../src/layui.js" charset="utf-8"></script>
<script type="text/javascript" src='../js/particles.js'></script>
<script type="text/javascript" src='../js/background.js'></script>

<script>
    layui.extend({
        admin: './static/js/admin'
    });
    layui.use(['form', 'element', 'jquery'], function () {
        var $ = layui.jquery

        $('#captchaImage').click(function () {
            $('#captchaImage').attr("src", "captcha.form?timestamp=" + (new Date()).valueOf());
        });
        $("#reset").click(function () {
            $("#password").val(null);
            $("#captcha").val(null);
            $('#captchaImage').attr("src", "captcha.form?timestamp=" + (new Date()).valueOf());
        });
        //监听提交
        $('input').keydown(function (event) {
            if (event.which == 13) {
                login();
            }
        });

        $("#login").on('click', function () {
            login();
        });

    });

    function login() {

        var newTable = {
            "user": $("#username").val(),
            "password": strEnc($("#password").val(), 'amoxu', 'amoxu', 'amoxu'),
            "mail": $("#captcha").val()
        };
        if (!newTable.user || !newTable.password || !newTable.mail) {
            layer.msg('请先输入必填项。', {icon: 5});
            return;
        }
        layer.msg('登录中...', {
            icon: 16
            , shade: 0.01
        }, 2000);
        $.ajax({
            type: 'post'
            , url: "/login"
            , data: newTable
            , dataType: 'json'
            , contentType: 'application/x-www-form-urlencoded;charset=UTF-8'
            , success: function (res) {
                if (res["status"] == 1) {
                    layer.msg(res['msg']);
                    setTimeout("$('#captchaImage').attr(\"src\", \"captcha.form?timestamp=\" + (new Date()).valueOf());", 2000);
                    return false;
                } else {
                    layer.msg("登录成功！");
                    localStorage.setItem('login', 1);
                }
                self.location = res["msg"];

            }
            , error: function (res) {
                layer.msg("错误码：" + res.status+"<br>"+res.statusText);
                setTimeout(" $(\"#reset\").click();", 2000)
            }
        });
        return false;
    }
</script>
</body>
</html>